import { Injectable } from '@angular/core';
import { BaseRequestOptions,Http,Response, HTTP_PROVIDERS,Headers,URLSearchParams} from '@angular/http';
import { GlobalService } from './global.service';
import { BaseService } from './base.service';

@Injectable()
export class UserService extends BaseService
{
    constructor(private http:Http,private globalService:GlobalService) {
      super()
    }

    login(name:string,password:string,callback:Function)
    {
      var url = BaseService.apiUrl + "/users/login";
      this.headers.set("x-username",name);
      this.headers.set("x-password",password);
      this.http.get(url,{headers:this.headers}).subscribe((data)=>{
        this.globalService.setUser(data.json());
        BaseService.user = data.json();
        callback && callback(data);
      },(error)=>{
        console.log(error);
      });
    }

    register(user){
      var u = JSON.stringify(user)
      var url = BaseService.apiUrl + "/users/register";
      return this.http.post(url,u,{headers:this.headers});
    }

    loginOut()
    {
    }
}
